﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

/** 
 ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
 * Description: 
 * Author: Heller (HellerSong@outlook.com)
 * CreationTime: 3/28/2015 3:44:29 PM
 ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** 
 **/
namespace DevGrammar.TestBasic
{
	[TestClass]
	public class TestIndexing
	{
		private class User
		{
			public int Id { get; set; }
			public String FirstName { get; set; }
			public String LastName { get; set; }

			public User(int id, String firstName, String lastName)
			{
				this.Id = id;
				this.FirstName = firstName;
				this.LastName = lastName;
			}
			/*
			 * Indexing, return type can be a string or int, bool and it can be overloaded;
			 *		You can call user[0] to get value for first name;
			 *		You can't call user[0] = "David" until you write set block;
			 */
			public String this[int index]
			{
				get // Only readable indexing
				{
					if (index == 0)
						return this.FirstName;
					else if (index == 1)
						return this.LastName;
					else
						return null;
				}
			}

		}

		[TestMethod]
		public void test_indexing()
		{
			User user = new User(1, "Heller", "Song");
			Console.WriteLine(user[1]);
		}
	}
}
